package com.jsh.erp.controller.activiti;

import com.jsh.erp.datasource.entities.activitti.SysDict;
import com.jsh.erp.datasource.entities.activitti.SysDictItem;
import com.jsh.erp.service.activiti.ISysDictItemService;
import com.jsh.erp.utils.BaseResponseInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 86138
 * @date 2023-03-06 21:35:24
 * @description
 */
@RestController
@RequestMapping("/sys/dictItem")
@Slf4j
public class SysDictItemController {

    @Autowired
    private ISysDictItemService sysDictItemService;

    /**
     * @Description 查询字典明细
     * @Param sysDictItem
     * @Param currentPage
     * @Param pageSize
     * @Param req
 * @Return com.jsh.erp.utils.BaseResponseInfo
     * @Author 86138
     * @Date 2023/3/6 21:56
     **/
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public BaseResponseInfo queryPageList(SysDictItem sysDictItem, @RequestParam(name="currentPage", defaultValue="0") Integer currentPage,
                                          @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req) {
        BaseResponseInfo res = new BaseResponseInfo();
        try {
            Map<String,Object> data = new HashMap<>();
            List<SysDictItem> list = sysDictItemService.selectDictItem(sysDictItem,currentPage,pageSize);
            if(list != null){
                data.put("rows",list);
                data.put("total",sysDictItemService.countDictItem(sysDictItem));
            }
            res.code = 200;
            res.data = data;
        } catch (Exception e) {
            e.printStackTrace();
            res.code = 500;
            res.data = "获取数据失败";
        }
        return res;
    }

}
